package com.k.kpp.config;

import org.apache.catalina.security.SecurityConfig;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 全局跨域配置
 * @author k
 */
@Configuration
@AutoConfigureBefore(SecurityConfig.class)
public class MyCorsConfig implements WebMvcConfigurer {
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(MyCorsConfig.class);
    @Override
    public void addCorsMappings(CorsRegistry registry){
        LOGGER.debug("跨域已设置");
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("*")
                .allowedHeaders("*")
                .allowCredentials(true)
                .maxAge(3600);
    }
}

